package com.vim.modules.web.utils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

/**
 * 代码自动生成工具-文件操作
 */
public class FileUtil {

	public FileUtil() {}

	public static void writeFile(String message, String path, boolean append) {
		OutputStreamWriter os = null;
		try {
			os = new OutputStreamWriter(new FileOutputStream(path, append),"UTF-8");
			os.write((message + System.getProperty("line.separator")));
			os.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				os.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	/**
	 * 递归构建目录
	 * @param path 目录路径
	 */
	public static void createDictory(String path) {
		File f = new File(path);
		File ft = f;
		while (!f.exists()) {
			ft = f;
			f = f.getParentFile();
		}
		if (f != ft) {
			ft.mkdir();
			createDictory(path);
		}
	}
}